package com.huawei.file;

import java.io.*;

/**
 * @description:
 * @author: lhh
 * @time: 2022/5/24
 */
public class FileOperationImpl implements FileOperation{
    @Override
    public void fileWriter(File file, String content, boolean append){
        try(BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(file,append)))){
            writer.write(content);
        }catch (FileNotFoundException e){
            e.printStackTrace();
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    @Override
    public String fileReader(File file){
        try(BufferedReader reader =new BufferedReader(new InputStreamReader(new FileInputStream(file)))) {
            String content = null;
            StringBuilder builder = new StringBuilder();
            while ((content=reader.readLine())!=null){
                builder.append(content).append("\n");
            }
            return builder.toString();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
